<?

//$p['orderby'] 可以设置成sums，couts ，就会按照统计的项来排序
//$p['sum']需要统计综合的项
//$p['count']需要统计条数的项（可以设置大小等于条件？）
//$p['table']
//$p['groupby'] 分组的项
//$p['orderby']." ".$p['orders']  排序
//LIMIT ".$p['limit'] 条数

function count_sum_groupby($p)
{



    if($p['count'])
    {
        $str_count=", count(".$p['count'].") as counts ";
    }

    if($p['sum'])
    {
        $str_sum=", sum(".$p['sum'].") as sums ";
    }

    if($p['limit'])
    {
        $str_limit=" LIMIT ".$p['limit'];
    }
    if($p['date']){
        $str_where =  ' where 1=1 '.$p['date'].' ';
    }


    if($p['table'])
    {
        $sqlstr="SELECT * ".$str_sum. $str_count." from ".$p['table'].$str_where." GROUP BY ".$p['groupby']." ORDER BY ".$p['orderby']." ".$p['orders'].$str_limit ;
    }



    if($p['log'])
    {
        echo $sqlstr;
    }


$results = mysql_query($sqlstr);

 while ($row = mysql_fetch_array($results))
 {
     $result[] = $row;
 }



return $result;
}
?>